<template>
  <div class="add-form">
    <el-dialog :title="titleInfo.text+titleInfo.pageTitle" :visible.sync="dialogFormVisible">
      <el-form
        :rules="ruleInline"
        ref="dataForm"
        :model="formBase"
        label-position="left"
        label-width="120px"
        style="width: 400px; margin-left:120px;"
      >
        <el-form-item :label="$t('table.company')" prop="company">
          <el-input v-model="formBase.company"></el-input>
        </el-form-item>
        <el-form-item :label="$t('table.kaleidoscope')" prop="shortName">
          <el-input v-model="formBase.shortName" ></el-input>
        </el-form-item>
        <el-form-item :label="$t('table.cityRegion')" prop="city" >
          <MyCity v-model="provAndCity" />
        </el-form-item>
        <el-form-item :label="$t('table.direction')" prop="tags">
          <el-input v-model="formBase.tags"></el-input>
        </el-form-item >
        <el-form-item :label="$t('table.remarks')" prop="remarks">
          <el-input  v-model="formBase.remarks"></el-input>
        </el-form-item>
        <!-- 按钮 -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleClose">{{$t('table.cancel')}}</el-button>
        <el-button type="primary" @click="createData">{{$t('table.confirm')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { update, add } from '@/api/hmmm/companys'
import MyCity from './MyCity'
export default {
  name: 'company-add',
  props: {
    titleInfo: {
      type: Object,
      required: true
    },
    formBase: {
      type: Object,
      required: true
    },
    provAndCity: {},
    ruleInline: {}
  },
  components: {
    MyCity
  },
  data () {
    return {
      dialogFormVisible: false
    }
  },
  methods: {
    // 弹层显示
    dialogFormV () {
      this.dialogFormVisible = true
    },
    dialogFormX () {
      this.formBase = {}
      this.provAndCity = {}
      this.dialogFormVisible = true
    },
    // 弹层隐藏
    dialogFormH () {
      // 移除校验
      this.formBase = {}
      this.provAndCity = {}
      this.$refs.dataForm.resetFields()
      this.dialogFormVisible = false
    },
    // 退出
    handleClose () {
      this.formBase = {}
      this.provAndCity = {}
      this.$emit('handleCloseModal')
    },

    // 表单提交
    createData () {
      this.formBase.city = this.provAndCity.city
      this.formBase.province = this.provAndCity.province
      this.formBase.isFamous = true
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          const data = {
            ...this.formBase
          }
          if (this.formBase.id) {
            update(data).then(() => {
              this.$emit('newDataes', this.formBase)
            })
            this.$message.success('编辑成功')
          } else {
            add(data).then(() => {
              this.$emit('newDataes', this.formBase)
            })
            this.$message.success('新增成功')
          }
          this.$emit('handleCloseModal')
        } else {
          this.$Message.error('*号为必填项!')
        }
      })
    }
  }
}
</script>

<style>

</style>
